import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

/**
 * ClassName test
 * Description TODO
 * Author Yanyan
 * Date 2025/11/5 9:54
 * Version 1.0
 */
public class Test {
    //奇数位于偶数之前
    //调整数组顺序使得奇数位于偶数之前。调整之后，不关心大小顺序。
    public static void sort(int[] array) {
        int left = 0;
        int right = array.length -1;
        while(left < right)
        {
            if(array[left] % 2 == 0)
            {
                while (left < right) {
                    if (array[right] % 2 != 0) {
                        int temp = array[left];
                        array[left] = array[right];
                        array[right] = temp;
                    }
                    right--;
                }
            }
            left++;
        }
    }

    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5, 6};
        sort(arr);
        System.out.println(Arrays.toString(arr));
    }


/*
    //给定一个大小为 n 的数组，找到其中的多数元素。多数元素是指在数组中出现次数 大于 ⌊ n/2 ⌋ 的元素。
    //你可以假设数组是非空的，并且给定的数组总是存在多数元素。
    public static int mul(int[] array) {
        for (int i = 0; i < array.length; i++) {
            int count = 0;//用于计数多少个和自己一样的元素（包括自己）
            for (int j = 0; j < array.length; j++) {
                if((array[i] ^ array[j]) == 0) {
                    count++;
                }
            }
            if(count > array.length / 2) {
                return array[i];
            }
        }
        return 0;
    }

    public static void main(String[] args) {
        int[] arr1 = {3, 2, 3};
        int[] arr2 = {2, 2, 1, 1, 2, 2};
        System.out.println(mul(arr1));
        System.out.println(mul(arr2));
    }

*/


/*

    //给定一个整型数组, 实现冒泡排序(升序排序)
    public static void bubble(int[] array) {
        for (int i = 0; i < array.length - 1; i++) {
            for (int j = 0; j < array.length - i - 1; j++) {
                if(array[j] > array [j + 1]) {
                    int temp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = temp;
                }
            }
        }
    }

    public static void main(String[] args) {
        int[] arr = new int[]{8, 3, 65, 2, 7, 8, 2, 4};
        bubble(arr);
        System.out.println(Arrays.toString(arr));
    }
*/

/*
    //给定一个有序整型数组, 实现二分查找
    public static void diFind(int[] array, int target) {
        int left = 0;
        int right = array.length - 1;
        boolean flag = false;
        while(left <= right) {
            int mid = (left + right) / 2;
            if(array[mid] == target) {
                flag = true;
                System.out.println("该数字对应下标为：" + mid);
                break;
            } else if (array[mid] > target) {
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }
        if(flag){
            System.out.println("找不到");
        }
    }

    public static void main(String[] args) {
        int[] arr1 = {1,2,4,7,9,23,45};
        int[] arr2 = {3,4,5,6,7};
        diFind(arr1,23);
        diFind(arr2,23);
    }
*/


/*
    //给定一个非空整数数组，除了某个元素只出现一次以外，其余每个元素均出现两次。找出那个只出现了一次的元素。
    public static int single(int[] array) {
        int ret = 0;
        for (int i : array) {
            ret ^= i;
        }//0和任何数异或得到任何数，相同数异或得到0
        return ret;
    }

    public static void main(String[] args) {
        int[] array1 = new int[]{2, 2, 1};
        System.out.println(single(array1));
        int[] array2 = new int[]{4, 1, 2, 1, 2};
        System.out.println(single(array2));
    }
*/


/*
    //给你一个整数数组 arr，
    // 请你判断数组中是否存在连续三个元素都是奇数的情况：
    // 如果存在，请返回 true ；否则，返回 false 。
    public static boolean three(int[] array) {
        for (int i = 0; i < array.length - 3; i++) {
            if ((array[i] % 2 != 0) && (array[i + 1] % 2 != 0) && (array[i + 2] % 2 != 0)) {
                return true;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        int[] array = new int[]{2, 6, 4, 1};
        System.out.println(three(array));
        int[] array2 = new int[]{1, 2, 34, 3, 4, 5, 7, 23, 12};
        System.out.println(three(array2));
    }
*/


/*

//    给定一个整数数组 nums 和一个整数目标值 target，
//    请你在该数组中找出 和为目标值 target 的那 两个 整数，
//    并返回它们的数组下标。
    public static String find(int[] array, int target) {
        String ret;
        for (int i = 0; i < array.length; i++) {
            for (int j = i; j < array.length; j++) {
                if((array[i] + array[j] == target)) {
                    ret = "[" + i + "," + j + "]";
                    return ret;
                }
            }
        }
        ret = "不存在";
        return ret;
    }

    public static void main(String[] args) {
        int[] nums = new int[]{2,7,11,15};
        int target = 9;
        System.out.println(find(nums,target));
    }
*/




/*
    public static void transform(int[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] *= 2;
        }
    }

    public static void main(String[] args) {
        int[] array = new int[]{1, 2, 3};
        transform(array);
        System.out.println(Arrays.toString(array));
    }
*/


/*
    public static String myToString(int[] array) {
        String ret = "[";
        for (int i = 0; i < array.length; i++) {
            ret += array[i];
            if(i != array.length - 1){
                ret += ", ";
            }
        }
        ret += "]";
        return ret;
    }

    public static void main(String[] args) {
        int[] array = new int[]{1, 2, 3, 4, 5};
        System.out.println(Arrays.toString(array));
        System.out.println(myToString(array));
    }
*/



/*
    //递归求斐波那契数列的第 N 项
    public static int fib(int n) {
        if(n == 1 || n == 2) {
            return 1;
        }
        int a = 1;
        int b = 1;
        int c = 0;
        for (int i = 3; i <= n; i++) {
            c = a + b;
            a = b;
            b = c;
        }
        return c;
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        System.out.println(fib(n));
        scan.close();
    }
*/

/*
    //返回的数字之和
    //写一个递归方法，输入一个非负整数，返回组成它的数字之和
    public static int Sum (int n) {
        if(n / 10 == 0) {
            return n;
        } else {
            return n % 10 + Sum(n / 10);
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        System.out.println(Sum(n));
        in.close();
    }
*/



/*
    //递归打印数字的每一位
    //按顺序打印一个数字的每一位(例如 1234 打印出 1 2 3 4) （递归）
    public static void Pri(int n) {
        if (n / 10 == 0) {
            System.out.print(n + " ");
        } else {
            Pri(n / 10);
            System.out.print(n % 10 + " ");
        }
    }

    public static void main(String[] args) {
        Pri(1234);
    }
*/

/*
    //递归求和
    //递归求 1 + 2 + 3 + ... + 10
    public static int Sum(int n) {
        if(n == 1) {
            return 1;
        } else {
            return n + Sum(n-1);
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        System.out.println(Sum(n));
        in.close();
    }
*/


/*
    //递归求 N 的阶乘
    public static int Fac(int n) {
        if(n == 1) {
            return 1;
        } else {
            return n*Fac(n-1);
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        System.out.println(Fac(n));
    }
*/


/*
    //求最大值方法的重载
    //在同一个类中定义多个方法：要求不仅可以求2个整数的最大值，还可以求3个小数的最大值？
    public static int Max(int a,int b) {
        if(a > b) {
            return a;
        } else {
            return b;
        }
    }

    public static double Max(double a,double b,double c) {
        if(a > b) {
            if(a > c) {
                return a;
            } else {
                return c;
            }
        } else if (b > c) {
            return b;
        } else {
            return c;
        }
    }

    public static void main(String[] args) {
        int a = 3,b = 4;
        double c = 2.1,d = 3.4,e = 7.4;
        System.out.println(Max(a,b));
        System.out.println(Max(c,d,e));
    }
*/


/*
    public static int fib(int n) {
        if(n == 1 || n ==2) {
            return 1;
        } else {
            return fib(n-1) + fib(n-2);
        }
    }


    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        System.out.println(fib(n));
    }

*/

/*
    public static int fac(int n) {
        int fac = 1;
        for (int i = 1; i <= n; i++) {
            fac *= i;
        }
        return fac;
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            sum += fac(i);
        }
        System.out.println(sum);
    }
*/


/*
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String password = "come_on_de_wei";
        boolean flag = false;
        for (int i = 0; i < 3; i++) {
            String putin = scan.nextLine();
            if (putin.equals(password)) {
                System.out.println("登录成功！");
                flag = true;
                break;
            } else {
                System.out.println("输入错误，请重新输入！");
            }
        }
        if(!flag) {
            System.out.println("错误次数过多，已关闭程序！");
        }
    }
*/



/*
    //完成猜数字游戏   ，用户输入数字，判断该数字是大于，小于，还是等于随机生成的数字，等于的时候退出程序。
    public static void main(String[] args) {
        Random random = new Random();
        int rad = random.nextInt(100);
        Scanner scan = new Scanner(System.in);
        while(true) {
            int putin = scan.nextInt();
            if(putin == rad) {
                System.out.println("猜对了");
                break;
            } else if(putin > rad) {
                System.out.println("猜大了");
            } else {
                System.out.println("猜小了");
            }
        }
    }
*/


/*    public static void main(String[] args) {
        //计算1/1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100 的值
        double sum = 0;
        int flag = 1;//用来切换符号
        for (int i = 1; i <= 100; i++) {
            sum += 1.0 / i * flag;
            flag = -flag;
        }
        System.out.println(sum);
    }*/



   /* public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            for(int i = 0; i < n; i++) {
                for(int j =0; j < n; j++) {
                    if(i == j || i + j == n -1) {
                        System.out.print('*');
                    }else
                        System.out.print(" ");
                }
                System.out.println();
            }

        }
    }*/

/*    //求2个整数的最大公约数
    public static void main(String[] args) {
        int a = 20;
        int b = 40;
        int c = a % b;
        while(c != 0) {
            a = b;
            b = c;
            c = a % b;
        }
        System.out.println(b);
    }*/


/*

    //递归的方式计算斐波那契数列
    public static int fib1(int n) {
        if(n == 1 || n ==2) {
            return 1;
        }
        return fib1(n - 1) + fib1(n - 2);
    }

    //迭代的方式计算斐波那契数列
    public static int fib2(int n) {
        if(n == 1 || n == 2) {
            return 1;
        }
        int a = 1;
        int b = 1;
        int c = 0;
        for (int i = 3; i <= n; i++) {
            c = a + b;
            a = b;
            b = c;
        }
        return c;
    }

    public static void main(String[] args) {
        System.out.println(fib1(10));
        System.out.println(fib2(10));
    }
*/


    /*  public static int fun(int n) {
        if(n / 10 == 0)
            return n;
        return n % 10 + fun(n / 10);
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int sum = fun(n);
        System.out.println(sum);
    }*/


    public static void main2(String[] args) {
        Random random = new Random();
        int num = random.nextInt(100);//[0,100)
        System.out.println(num);
        Scanner scan = new Scanner(System.in);
        int i = scan.nextInt();
        System.out.println(i);

    }

    //输出一个整数的每一位，如：123的每一位是3，2，1
    public static void main1(String[] args) {
        int num = 123;
        int temp = num;
        int count = 0;
        while (temp > 0) {
            count++;
            temp /= 10;
        }
        temp = num;
        for (int i = 0; i < count; i++) {
            System.out.print((temp % 10) + " ");
            temp /= 10;
        }
    }
}
